#define _GNU_SOURCE
#include "fastxml.h"

// 声明安全版本的解析函数
xml_document_t* xml_parse_string_safe(const char *xml_string);

int main() {
    printf("安全版本XML解析测试...\n");
    
    const char *simple_xml = "<root>Hello World</root>";
    
    printf("解析XML: %s\n", simple_xml);
    
    xml_document_t *doc = xml_parse_string_safe(simple_xml);
    if (doc) {
        printf("解析成功!\n");
        if (doc->root) {
            printf("根节点名称: %s\n", doc->root->name ? doc->root->name : "NULL");
            printf("根节点内容: %s\n", doc->root->content ? doc->root->content : "NULL");
        } else {
            printf("根节点为空!\n");
        }
        xml_free_document(doc);
    } else {
        printf("解析失败!\n");
    }
    
    printf("\n测试复杂XML...\n");
    
    const char *complex_xml = 
        "<bookstore>\n"
        "  <book id=\"1\">\n"
        "    <title>C Programming</title>\n"
        "    <author>K&R</author>\n"
        "  </book>\n"
        "</bookstore>\n";
    
    printf("解析复杂XML...\n");
    
    xml_document_t *doc2 = xml_parse_string_safe(complex_xml);
    if (doc2) {
        printf("复杂XML解析成功!\n");
        if (doc2->root) {
            printf("根节点: %s\n", doc2->root->name ? doc2->root->name : "NULL");
        }
        xml_free_document(doc2);
    } else {
        printf("复杂XML解析失败!\n");
    }
    
    return 0;
}